package com.sjz.han.industry.wxapi;







import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;

import com.sjz.han.industry.MainActivity;
import com.sjz.han.industry.R;
import com.sjz.han.industry.base.AppConfig;
import com.sjz.han.industry.utils.ShareUtils;
import com.sjz.han.industry.utils.ToastUtils;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
	
	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
	
    private IWXAPI api;
	ShareUtils shareUtils = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
		setContentView(R.layout.pay_result);
		shareUtils = new ShareUtils(this);
		this.getWindow().getDecorView().setBackgroundColor(Color.TRANSPARENT);
		api = WXAPIFactory.createWXAPI(this, WeiXinPayMethod.APP_ID);
		api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {
		ToastUtils.popUpToast("是否成功==="+resp.errCode);
		if (resp.errCode == 0) {
			shareUtils.setLevel("1");
			startActivity(new Intent(this,MainActivity.class));
			ToastUtils.popUpToast("支付成功，恭喜");
		} else {
			ToastUtils.popUpToast("充值失败，请稍后再试");
		}
		finish();
	}
}